﻿/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2012-2018. All rights reserved.
 * Description:
 * Author: 辛爱国 x30005137
 * Create: 2020-07-28
 * Notes: 无
 */

#include <QGraphicsDropShadowEffect>
#include <qapplication.h>
#include <QDesktopWidget>
#include <qscreen.h>
#include "qdebug.h"
#include "mainwindow.h"
#include "settingmenudialog.h"
SettingMenuDialog::SettingMenuDialog(QWidget *parent) : HWDialog(parent)
{

    setupUi(this);
    setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog | Qt::WindowStaysOnTopHint);
    this->setAttribute(Qt::WA_TranslucentBackground);
    // 区别对待
    //pushButtonSetCode->hide();
    m_parent = parent;
    QGraphicsDropShadowEffect *shadow_effect = new QGraphicsDropShadowEffect(this);
    shadow_effect->setOffset(0, 0);
    shadow_effect->setColor(Qt::gray);
    shadow_effect->setBlurRadius(10);              // 设置阴影参数半径10
    this->widgetSet->setGraphicsEffect(shadow_effect);
    this->pushButtonAbout->setCursor(QCursor(Qt::PointingHandCursor));
    //this->pushButtonLogInfo->setCursor(QCursor(Qt::PointingHandCursor));
    this->pushButtonSetting->setCursor(QCursor(Qt::PointingHandCursor));
    this->pushButtonSetting->installEventFilter(this);
    //this->pushButtonLogInfo->installEventFilter(this);
    this->pushButtonAbout->installEventFilter(this);
    //this->pushButtonSetCode->installEventFilter(this);
    saveChildrenInfo();
}


void SettingMenuDialog::leaveEvent(QEvent *e) {}
SettingMenuDialog::~SettingMenuDialog() {}

bool SettingMenuDialog::eventFilter(QObject *watched, QEvent *event)
{
    if (watched == this->pushButtonSetting && event->type() == QEvent::Enter) {
        QIcon icon(":/image/images/76.png");
        this->pushButtonSetting->setIcon(icon);
    } else if (watched == this->pushButtonSetting && event->type() == QEvent::Leave) {
        QIcon icon(":/image/images/78.png");
        this->pushButtonSetting->setIcon(icon);
    }
    /*
    else if (watched == this->pushButtonLogInfo && event->type() == QEvent::Enter) {
        QIcon icon(":/image/images/71.png");
        this->pushButtonLogInfo->setIcon(icon);
    } else if (watched == this->pushButtonLogInfo && event->type() == QEvent::Leave) {
        QIcon icon(":/image/images/74.png");
        this->pushButtonLogInfo->setIcon(icon);
    }
    */
    else if (watched == this->pushButtonAbout && event->type() == QEvent::Enter) {
        QIcon icon(":/image/images/67.png");
        this->pushButtonAbout->setIcon(icon);
    } else if (watched == this->pushButtonAbout && event->type() == QEvent::Leave) {
        QIcon icon(":/image/images/70.png");
        this->pushButtonAbout->setIcon(icon);
    }
    /*
    else if (watched == this->pushButtonSetCode && event->type() == QEvent::Enter) {
        QIcon icon(":/image/images/80.png");
        this->pushButtonSetCode->setIcon(icon);
    } else if (watched == this->pushButtonSetCode && event->type() == QEvent::Leave) {
        QIcon icon(":/image/images/82.png");
        this->pushButtonSetCode->setIcon(icon);
    }
    */
    return QObject::eventFilter(watched, event);
}
void SettingMenuDialog::keyPressEvent(QKeyEvent *event)
{
    emit leaveOut();
    if (m_parent) {
        ((MainWindow *)m_parent)->keyPressEvent(event);
    }
}

void SettingMenuDialog::on_pushButtonAbout_clicked()
{
    emit leaveOut();
    if (m_parent) {
        ((MainWindow *)m_parent)->slotpushButtonAbout();
    }
}
void SettingMenuDialog::on_pushButtonLogInfo_clicked()
{
    emit leaveOut();
    if (m_parent) {
        ((MainWindow *)m_parent)->slotpushButtonLogInfo();
    }
}

void SettingMenuDialog::on_pushButtonSetCode_clicked()
{
    emit leaveOut();
    if (m_parent) {
        ((MainWindow *)m_parent)->slotpushButtonSetCode();
    }
}
void SettingMenuDialog::on_pushButtonSetting_clicked()
{
    emit leaveOut();
    if (m_parent) {
        ((MainWindow *)m_parent)->slotpushButtonSetting();
    }
}
void SettingMenuDialog::on_pushButtonMinExit_clicked()
{
    emit leaveOut();
    if (m_parent) {
        qDebug() << "exit... SettingMenuDialog::on_pushButtonMinExit_clicked... ";
        ((MainWindow *)m_parent)->close();
    }
}
void SettingMenuDialog::on_pushButtonConnect_clicked()
{
    emit leaveOut();
#if defined(IDEASHAREKEY)
    ((MainWindow *)m_parent)->showIdeaShareKey();
#endif
}

void SettingMenuDialog::on_pushButtonShareMenu_clicked()
{
    if (m_parent) {
        ((MainWindow *)m_parent)->on_pushButtonShare_clicked();
    }
}
void SettingMenuDialog::on_pushButtonShowMainWindow_clicked()
{
    emit leaveOut();
    if (m_parent) {
        ((MainWindow *)m_parent)->showNormal();
        ((MainWindow *)m_parent)->activateWindow();
    }
}
void SettingMenuDialog::on_pushButtonStopShareMenu_clicked()
{
    if (m_parent) {
        ((MainWindow *)m_parent)->on_pushButtonStop_clicked();
    }
}
bool SettingMenuDialog::event(QEvent *event)
{
    if (event->type() == QEvent::ActivationChange) {
        if (QApplication::activeWindow() != nullptr) {
            qDebug() << "current activationName " << QApplication::activeWindow()->objectName();
        }
        if (QApplication::activeWindow() != this) {
            bool needHide = true;
            if (m_parent) {
                needHide = ((MainWindow *)m_parent)->clickMorePushbutton();
            }
            if (needHide)
                emit leaveOut();
        }
    }
    return QWidget::event(event);
}
